﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ProductDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["idProduct"] != null)
            {
                int id = int.Parse(Request.QueryString["idProduct"].ToString());
                ChoDienTuDataContext cdt = new ChoDienTuDataContext();
                PDetail.DataSource = cdt.Select_ProductByID(id);
                PDetail.DataBind();
            }
        }
    }
    public void ShoppingCart_Add(object sender, EventArgs e)
    {
        //clsShoppingCart Cart = (clsShoppingCart)Session["ShoppingCart"];
        //ImageButton btn = (ImageButton)sender;
        //ImageButton ibtProduct = (ImageButton)(FormView1.FindControl("ibtnBuy"));
        //int idProduct = int.Parse(ibtProduct.CommandArgument.ToString());
        //TextBox txtQuantity = (TextBox)(FormView1.FindControl("txtQuantity"));
        //int Quantity = int.Parse(txtQuantity.Text);
        //Cart.Add(idProduct, Quantity);
        //ASP.masterpage_master master = (ASP.masterpage_master)this.Master;
        //master.RefreshShoppingCartInfo();

        int id = 0;
        if (Request.QueryString["idProduct"] != null)
        {
            id = int.Parse(Request.QueryString["idProduct"].ToString());
        }
        else
        {
            return;
        }

        MyCart cart = (MyCart)Session["cart"];
        TextBox txtQuantity = (TextBox)(PDetail.FindControl("txtQuantity"));
        int Quantity = int.Parse(txtQuantity.Text);
        CartItem item = new CartItem(id, Quantity);
        cart.AddItem(item);

        ASP.masterpage_master master = (ASP.masterpage_master)this.Master;
        master.RefreshShoppingCartInfo();
    }
}